package com.aistar.controller;

import com.aistar.service.CompanyService;
import com.aistar.service.impl.CompanyServiceImpl;
import com.aistar.util.ServerResponse;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "CompanyServlet")
public class CompanyServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String op = request.getParameter("op");
        switch (op){
            case "detail":detail(request,response);
        }
    }
    private void detail(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      Integer id = Integer.valueOf( request.getParameter("id"));
        CompanyService service = new CompanyServiceImpl();

        ServerResponse serverResponse = service.getById(id);

        request.setAttribute("company",serverResponse.getData());
        request.getRequestDispatcher("/company/detail.jsp").forward(request,response);
    }
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
